HI! 我是Maple 剛滿20歲沒多久的小朋友 請ㄅ要欺負窩QAQ
YEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE~~~~
今天是第三十天耶~
不過我之後還是會寫文章和大家分享我的大學生活ㄉ~~(想到就發)~~
今天一整天都在寫code的啦~~~
首先是因為資料結構實習平均分數太低,助教為了不讓我們太多人被當而考得加分題,總共兩題,都是CPE的題目,有人不知道CPE是甚麼ㄇ,然後我兩題都有寫出來(好爽),可是我原始分數超低ㄏㄏ(58分),應該會加到20分變成78分QQ
第二個是物件導向實習,也是在寫code,在自定義的class使用Static,然後在main function裡面作一些事情實作來確定我們這些學生會使用Static
這是自定義的class
package test;
public class HotDogStand {
private static int totalSold;
private String standName;
private int sold;
//construct
public HotDogStand(){
standName = "N/A";
}
public HotDogStand(String standName){
this.standName = standName;
}
public void setsold(int sold) {
this.sold = sold;
}
public void setstandName(String standName) {
this.standName = standName;
}
public int getsold() {
return sold;
}
public String getstandName() {
return standName;
}
public void justSold(int sold){
this.sold += sold;
totalSold = totalSold + sold;
}
public static int getTotalSold() {
return HotDogStand.totalSold;
}
}
這是主程式
import test.HotDogStand;
public class main {
public static void main(String[] args) {
HotDogStand Store01 = new HotDogStand("Taipei Branch");
HotDogStand Store02 = new HotDogStand("Taichung Branch");
HotDogStand Store03 = new HotDogStand("Kaohsiung Branch");
Store01.justSold(5);
Store01.justSold(7);
Store01.justSold(9);
Store02.justSold(1);
Store02.justSold(4);
Store02.justSold(5);
Store03.justSold(6);
Store03.justSold(7);
Store03.justSold(9);
System.out.printf("Stand Name: %s %5d\n", Store01.getstandName(), Store01.getsold());
System.out.printf("Stand Name: %s %3d\n", Store02.getstandName(), Store02.getsold());
System.out.printf("Stand Name: %s %2d\n", Store03.getstandName(), Store03.getsold());
System.out.printf("Total Sold: %d\n", HotDogStand.getTotalSold());
}
}